import game_object
pi=3.1415926535897931
class scripted_object(game_object.game_object):
	"""A game object is one that is in the physical game, has to move, and generate collision events when they occur."""
	def __init__(self,actions,senses,object_type,object_num,max_velocity,max_heading_diff,radius,graphics_draw,graphics_die,pos,heading,im_file):
		game_object.game_object.__init__(self,actions,senses,object_type,object_num,max_velocity,max_heading_diff,radius,graphics_draw,graphics_die,pos,heading,im_file)
		# Tunable constants
		self.max_goal_heading_diff=pi/4

	def strat_move_towards(self,direction):
		"""Move towards something, given a direction"""
		self.actions['turn_rel'](self.object_num,-direction)
		if direction < self.max_goal_heading_diff:
			self.actions['move_rel_object'](self.object_num,[0,float(1e1000)])
			
	def think(self):
		"""Called to allow the agent to sense/think/act"""
		# The states are 0='I have the ball', 1='Someone on my team has the ball', 2='Enemy has the ball', 3=Loose Ball
		# Sense Stage
		state=self.senses['state']()
		goal_distance,goal_direction=self.senses['goal']()
		ball_distance,ball_direction=self.senses['ball']()
		
		if state==0: # I have the ball
		# Useful sensors:  Direction/distance to the goal 'point', pie slices of teammates, pie slices of enemies
			self.strat_move_towards(goal_direction)
		elif state==1: # Someone on my team has the ball
			self.strat_move_towards(goal_direction)
		elif state==2: # The enemy has the ball
			self.strat_move_towards(ball_direction)
		elif state==3: # The ball is loose
			self.strat_move_towards(ball_direction)
		else:
			raise StandardError,'Invalid State'

		return
	def draw(self):
		"""Draws the object using the provided callback function.  This can use member variables to control different frames of animation to be drawn.  The draw function must be able to setup the initial representation aswell as update it."""
		self.graphics_draw(self.object_num,self.pos,self.heading,self.graphics_state,self.im_file)
	def die(self):
		"""Remove the graphical representation of the object"""
		self.graphics_die(self.object_num)
